<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

/**
 * App\GamePrizeRecord
 *
 * @property int $id
 * @property int|null $user_id
 * @property int|null $game_id
 * @property string|null $prize_id
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @property-read \App\GamePrize|null $gamePrize
 * @property-read \App\Http\Controllers\Admin\Member\Repository\Member|null $member
 * @method static \Illuminate\Database\Eloquent\Builder|\App\GamePrizeRecord whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\GamePrizeRecord whereGameId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\GamePrizeRecord whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\GamePrizeRecord wherePrizeId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\GamePrizeRecord whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\GamePrizeRecord whereUserId($value)
 * @mixin \Eloquent
 */
class GamePrizeRecord extends Model
{
    //
    public function getCreatedAtAttribute($date)
    {
        // 默认100天前输出完整时间，否则输出人性化的时间
        if (Carbon::now() > Carbon::parse($date)->addDays(10)) {
            return $date;
        }
        return Carbon::parse($date)->diffForHumans();
    }
    public function member(){
        return $this->belongsTo('App\Http\Controllers\Admin\Member\Repository\Member','user_id');
    }
    public function gamePrize(){
        return $this->belongsTo('App\GamePrize','prize_id');
    }
    
}
